#include "loadTexture.h"
#include "myTexture.h"
#include <iostream>
#include <string>
#include <sstream>
#include <GL/glut.h>
using namespace std;


#ifndef SKYBOX_H
#define SKYBOX_H
class Skybox
{
private: 
	GLuint texturaID[6];
	float x,y,z;
	float width,height,length;


public:
	Skybox() {};
	Skybox(float x, float y, float z, float width, float height, float length)
	{
		//glGenTextures(6, &texturaID[0]);
		glGenTextures(6, texturaID);
		for(int i=1;i<7;i++)
		{
			stringstream _path;
			_path<<"sky"<<i<<".jpg"; 
			string spath=_path.str();
			

			char * path = new char [spath.size()+1];
			strcpy (path, spath.c_str());
			MyTexture textura=LoadImageToTexture(path);

			glBindTexture(GL_TEXTURE_2D, texturaID[i-1]);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, textura.w, textura.h, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)textura.texture );
			
		}
		this->x = x - width  / 2;  
		this->y = y - height / 2;  
		this->height=height;
		this->length=length;
		this->width=width;
	}
	~Skybox(){};

	void draw()
	{
	glPushMatrix();
	glPushAttrib(GL_ENABLE_BIT);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glDisable(GL_BLEND);
 
    // Just in case we set all vertices to white.
    glColor4f(1,1,1,1);

    glBindTexture(GL_TEXTURE_2D,texturaID[5]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f( width, -height, -length );
        glTexCoord2f(1, 0); glVertex3f( -width, -height, -length );
        glTexCoord2f(1, 1); glVertex3f( -width, height, -length );
        glTexCoord2f(0, 1); glVertex3f(  width, height, -length );
    glEnd(); 
 
   
    glBindTexture(GL_TEXTURE_2D,texturaID[0]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f( height, -height, length );
        glTexCoord2f(1, 0); glVertex3f( height, -height, -length );
        glTexCoord2f(1, 1); glVertex3f( height, height, -length );
        glTexCoord2f(0, 1); glVertex3f( height, height, length );
    glEnd();
 
    
    glBindTexture(GL_TEXTURE_2D,texturaID[4]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f( -height, -height, length );
        glTexCoord2f(1, 0); glVertex3f( height, -height, length );
        glTexCoord2f(1, 1); glVertex3f( height, height, length );
        glTexCoord2f(0, 1); glVertex3f( -height, height, length );
 
    glEnd();
 
   
    glBindTexture(GL_TEXTURE_2D,texturaID[1]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f( -height, -height, -length );
        glTexCoord2f(1, 0); glVertex3f( -height, -height, length );
        glTexCoord2f(1, 1); glVertex3f( -height, height, length );
        glTexCoord2f(0, 1); glVertex3f( -height, height, -height );
    glEnd();
 
  
    glBindTexture(GL_TEXTURE_2D,texturaID[2]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 1); glVertex3f( -height, height, -length );
        glTexCoord2f(0, 0); glVertex3f( -height, height, length );
        glTexCoord2f(1, 0); glVertex3f( height, height, length );
        glTexCoord2f(1, 1); glVertex3f( height, height, -height );
    glEnd();
 
    
    glBindTexture(GL_TEXTURE_2D,texturaID[3]);
    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f( -height, -height, -length );
        glTexCoord2f(0, 1); glVertex3f( -height, -height, length );
        glTexCoord2f(1, 1); glVertex3f( height, -height, length );
        glTexCoord2f(1, 0); glVertex3f( height, -height, -length);
    glEnd();
 
   
    glPopAttrib();
    glPopMatrix();
	 
	}

};
#endif